package cn.zhc.com.utils;

import android.support.annotation.Nullable;
import android.text.Html;
import android.text.Spanned;
import android.text.TextUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by SpringLoading on 2017/8/26.
 */

public class UtilsText {

    /**
     * 判断当前号码是否是正确的手机号码
     */
    public static boolean checkPhoneNumber(@Nullable String phoneNumber) {
        boolean isValid = false;
        CharSequence inputStr = phoneNumber;
        //正则表达式
//        String phone="^1[34578]\\d{9}$" ;
        String phone="^1[0-9]\\d{9}$" ;
        Pattern pattern = Pattern.compile(phone);
        Matcher matcher = pattern.matcher(inputStr);

        if(matcher.matches()) {
            isValid = true;
        }
        return isValid;
    }

    /**
     * 判断当前号码是否是正确的手机号码
     */
    public static boolean isEmpty(String phoneNumber) {
        if (TextUtils.isEmpty(phoneNumber) || "null".equals(phoneNumber.toLowerCase()))
            return true;
        return false;
    }

    /**
     *
     * @param color "#fffffff"
     * @param changeBody 变化的部分
     * @return
     */
    public static Spanned getColorText(String color, String changeBody){
        String str = "<font color='"+color+"'>"+changeBody+"</font>";
        return Html.fromHtml(str);


    }
}
